<template>
  <div>
    <el-drawer
      :visible.sync="_visible_"
      :direction="direction"
      :with-header="false"
      :size="width"
    >
      <!-- 抽屉顶部关闭区域 -->
      <div class="header-self">
        <div class="header-left" @click="closeDrawer">
          <i :class="headIcon"></i>
          <div>{{ title }}</div>
        </div>
        <el-divider direction="vertical"></el-divider>
        <div class="header-right">
          <div>{{ content }}</div>
          <el-tag type="danger">重要</el-tag>
        </div>
      </div>
      <!-- 内容 -->
      <slot />
    </el-drawer>
  </div>
</template>

<script>
export default {
  props: {
    // 控制抽屉关闭的开关
    visible: {
      type: Boolean,
      required: true,
    },
    // 控制抽屉的宽度
    width: {
      type: String | Number,
      required: false,
      default: "30%",
    },
    // 控制抽屉的打开方向
    direction: {
      type: String,
      required: false,
      default: "rtl",
    },
    // 控制头部的icon图标
    headIcon: {
      type: String,
      required: false,
      default: "el-icon-arrow-left",
    },
    // 控制头部icon旁的文字
    title: {
      type: String,
      required: false,
      default: "关闭",
    },
    content: {
      type: String,
      required: false,
      default: "详情",
    },
  },
  data() {
    return {};
  },
  methods: {
    closeDrawer() {
      this.$emit("update:visible", false);
    },
  },
  computed: {
    _visible_: {
      get() {
        return this.visible;
      },
      set(val) {
        this.$emit("update:visible", val);
      },
    },
  },
};
</script>

<style lang="less" scoped>
.header-self {
  display: flex;
  padding-left: 20px;
  align-items: center;
  line-height: 50px;
  border-bottom: 1px solid @lineColor;
  .header-left {
    display: flex;
    // margin-right: 40px;
    cursor: pointer;
    i {
      margin-right: 5px;
      font-size: 18px;
      align-self: center;
    }
    div {
      font-size: 14px;
      font-weight: 500;
    }
  }
  .header-right {
    display: flex;
    font-size: 18px;
    color: #333333;
  }
  .el-divider {
    margin: 0 13px;
  }
  .el-tag {
    height: 25px;
    line-height: 25px;
    padding: 0 5px;
    margin: 0 8px;
    border: 0;
    align-self: center;
    &.el-tag--danger {
      color: #e44c4c;
    }
  }
}
</style>
